<?php
namespace app\index\controller;

use app\model\ClassDepartmentModel;
use app\model\ClassModel;
use app\model\DepartmentModel;
use app\model\UserClassModel;
use app\model\UserModel;

class Index
{
    public function index()
    {
        return app()->getRootPath();
    }

    /**
     * 测试模型是否正常使用
     */
    public function getAttrUseBase()
    {
        echo UserModel::find(1)->user_id, PHP_EOL;
        echo ClassModel::find(1)->class_id, PHP_EOL;
        echo DepartmentModel::find(1)->department_id, PHP_EOL;
        echo UserClassModel::find(3)->user_class_id, PHP_EOL;
        echo ClassDepartmentModel::find(1)->class_department_id, PHP_EOL;
    }

    /**
     * 使用获取器简单修改获取到的数据
     */
    public function getUserInfoBase() {
        $userTest = UserModel::select()->toArray();
        dump($userTest);
    }

    /**
     * 使用获取器得到其他表字段值
     */
    public function getUserInfoAdvanced() {
        $userTest = UserModel::select()->append(["class_id","class_name","department_id","department_name"],true)->toArray();
        dump($userTest);
    }

    public function hasUserInfo() {
        $userTest = UserModel::select()->append(["class_id","class_name","department_id","department_name"])->toArray();
        dump($userTest);
    }

}
